<template>
  <div class="list-tabs__item">
    <el-tabs>
      <el-tab-pane
        v-for="(item, index) in list"
        :key="index"
        :label="item.title"
      >
        <el-scrollbar max-height="300px">
          <ul>
            <li
              class="container"
              v-for="(innerItem, innerIndex) in item.content"
              :key="innerIndex"
              @click="clickItem(innerItem, innerIndex)"
            >
              <div class="avatar" v-if="innerItem.avatar">
                <el-avatar size="small" :src="innerItem.avatar"></el-avatar>
              </div>
              <div class="content">
                <div v-if="innerItem.title" class="title">
                  <div>{{ innerItem.title }}</div>
                  <el-tag
                    v-if="innerItem.tag"
                    size="small"
                    :type="innerItem.tagType || 'primary'"
                    >{{ innerItem.tag }}</el-tag
                  >
                </div>
                <div class="time" v-if="innerItem.desc">
                  {{ innerItem.desc }}
                </div>
                <div class="time" v-if="innerItem.time">
                  {{ innerItem.time }}
                </div>
              </div>
            </li>
          </ul>
          <div class="actions">
            <div
              class="a-item"
              v-for="(action, i) in actions"
              :key="i"
              @click="clickAction(action, i)"
            >
              <div class="a-icon" v-if="action.icon">
                <component :is="`el-icon-${toLine(action.icon)}`"></component>
              </div>
              <div class="a-text">{{ action.text }}</div>
            </div>
          </div>
        </el-scrollbar>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script setup lang="ts">
import { PropType } from "vue";
import { toLine } from "@/utils/index.ts";
import { ListItem, ListOptions, ActionOptions } from "./types.ts";
defineProps({
  list: {
    type: Array as PropType<ListOptions[]>,
    required: true,
    default: () => [],
  },
  actions: {
    type: Array as PropType<ActionOptions[]>,
    default: () => [],
  },
});

let emits = defineEmits(["clickItem", "clickAction"]);

let clickItem = (item: ListItem, index: number) => {
  emits("clickItem", { item, index });
};
let clickAction = (item: ActionOptions, index: number) => {
  emits("clickAction", { item, index });
};
</script>

<style lang="scss" scoped>
.demo-tabs > .el-tabs__content {
  padding: 32px;
  color: #6b778c;
  font-size: 32px;
  font-weight: 600;
}
.container {
  display: flex;
  align-items: center;
  padding: 12px 20px;
  cursor: pointer;
  &:hover {
    background: #e6f6ff;
  }
  .avatar {
    flex: 1;
  }
  .content {
    flex: 3;
    .title {
      display: flex;
      align-items: center;
      justify-content: space-between;
    }
    .time {
      font-size: 12px;
      color: #999;
      margin-top: 4px;
    }
  }
}
.actions {
  height: 50px;
  display: flex;
  align-items: center;
  border-top: 1px solid #eee;
  .a-item {
    height: 50px;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-right: 1px solid #eee;

    .a-icon {
      margin-right: 4px;
      position: relative;
      top: 2px;
    }
    &:last-child {
      border-right: none;
    }
  }
}
</style>
